home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
asm_msc1.arc
/
RWSUB2I.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-11-20
|
3KB
|
100 lines
; RWSUB2I - disk read/write subroutine for interpretive BASIC
; Copyright 1983 Data Base Decisions
;
; Note: This routine requires DOS 2.00 or later!
;
; CALL RWSUB2I(STACK$,FIL$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
; STACK$ is a temporary stack (not needed by compiled version)
; FIL$ is the file name in ASCIIZ format
; FUNC% indicates reading (=0), writing (=1), or creating (and writing =2)
; SBYTELO% is the low part of the starting byte
; SBYTEHI% is the high part of the starting byte (HI*65536+LO)
; NOBYTES% is the number of bytes to be read/written
; DTASEG% is the segment to be read into or written from
; RETCODE% is an error return code (non-zero if an error occurred)
skip equ 1 ; 2 for compiled, 1 for interpretive
cseg segment para public 'code'
public rwsub2i
rwsub2i proc far
assume cs:cseg,ds:nothing,ss:nothing,es:nothing
push bp
mov bp,sp
; use passed stack
mov di,sp ; save orig sp
mov si,[bp+20] ; point to STACK$
mov al,[si] ; get length
mov ah,0
add si,skip
add ax,[si] ; add start addr
dec ax ; down by 1
mov sp,ax ; new sp
push di ; save orig sp on new stack
; open the file
mov si,[bp+18] ; point to FIL$
add si,skip
mov dx,[si] ; point to file name
mov si,[bp+16] ; point to FUNC%
mov al,[si] ; get access code in al
mov ah,3dh
cmp al,2 ; create?
jnz p010 ; no
dec ah
mov cx,0 ; clear attributes
p010: int 21h ; open the file
jc p030 ; error?
; set the file pointer
mov bx,ax ; get the handle
mov si,[bp+12] ; point to SBYTEHI%
mov cx,[si] ; put it in cx
mov si,[bp+14] ; point to SBYTELO%
mov dx,[si] ; put it in dx
mov ah,42h ; move file read/write pointer
mov al,0 ; method 0 - offset from beginning of file
int 21h ; position in the file
jc p030 ; error?
; read/write the file
mov si,[bp+10] ; point to NOBYTES%
mov cx,[si] ; number of bytes to read/write
mov si,[bp+16] ; point to FUNC%
mov ah,[si] ; 0 for read, 1 for write
cmp ah,2 ; create?
jnz p020 ; no
dec ah ; yes - make it a write
p020: add ah,3fh ; setup interrupt function
push ds
mov si,[bp+8] ; point to DTASEG%
mov dx,[si]
mov ds,dx ; now in ds
xor dx,dx ; ds:dx contains DTA
int 21h ; read/write the file
pop ds ; get orig ds
jc p030 ; error?
mov si,[bp+10] ; point to NOBYTES%
mov [si],ax ; save bytes read/written
; close the file
mov ah,3eh
int 21h ; close the file
jnc p040 ; no error
p030: ; error handler
mov si,[bp+6] ; point to RETCODE%
mov [si],ax ; save the error
p040: ; return to caller
pop di ; get orig sp
mov sp,di ; back to orig stack
pop bp
ret 16
rwsub2i endp
cseg ends
end